﻿using System;
using System.Diagnostics;
using System.Threading;
using System.Windows;
using System.Windows.Controls;

namespace SLClient.CustomerControls
{
    public partial class BonusControl : UserControl
    {
        private BonusStatus _bonusStatus;
        private PlayDataInfo _m_CurrentPlayDataInfo;        
        private EventHandler _BonusStatusChanged;

        public event EventHandler BonusStatusChanged
        {
            add
            {
                EventHandler handler2;
                EventHandler bonusStatusChanged = this._BonusStatusChanged;
                do
                {
                    handler2 = bonusStatusChanged;
                    EventHandler handler3 = (EventHandler)Delegate.Combine(handler2, value);
                    bonusStatusChanged = Interlocked.CompareExchange<EventHandler>(ref this._BonusStatusChanged, handler3, handler2);
                }
                while (bonusStatusChanged != handler2);
            }
            remove
            {
                EventHandler handler2;
                EventHandler bonusStatusChanged = this._BonusStatusChanged;
                do
                {
                    handler2 = bonusStatusChanged;
                    EventHandler handler3 = (EventHandler)Delegate.Remove(handler2, value);
                    bonusStatusChanged = Interlocked.CompareExchange<EventHandler>(ref this._BonusStatusChanged, handler3, handler2);
                }
                while (bonusStatusChanged != handler2);
            }
        }

        public BonusControl(PlayDataInfo playDataInfo)
        {
            this.InitializeComponent();
            this._m_CurrentPlayDataInfo = playDataInfo;
            base.DataContext=new BonusControlViewModel(this, playDataInfo);
        }

        public void Init(PlayDataInfo pdi)
        {
            this.CurrentPlayDataInfo = pdi;
            this.bonusContent.DataContext=this.CurrentPlayDataInfo.LastPlayData;
        }

        public BonusStatus CurrentBonusStatus
        {
            get
            {
                return this._bonusStatus;
            }
            set
            {
                this._bonusStatus = value;
                (base.DataContext as BonusControlViewModel).CurrentPlayDataInfo.IsLoading = true;
                if (this._bonusStatus == BonusStatus.StartOpen)
                {
                    switch ((base.DataContext as BonusControlViewModel).CurrentPlayDataInfo.lotteryCatagoryId)
                    {
                        case 1:
                            (base.DataContext as BonusControlViewModel).CurrentPlayDataInfo.Init(1, "ssq");
                            break;

                        case 2:
                            (base.DataContext as BonusControlViewModel).CurrentPlayDataInfo.Init(2, "sd");
                            break;

                        case 3:
                            (base.DataContext as BonusControlViewModel).CurrentPlayDataInfo.Init(3, "ssc");
                            break;
                    }
                }
                if (this._BonusStatusChanged != null)
                {
                    this._BonusStatusChanged(this, null);
                }
            }
        }

        public PlayDataInfo CurrentPlayDataInfo
        {
            get
            {
                return this._m_CurrentPlayDataInfo;
            }
            set
            {
                this._m_CurrentPlayDataInfo = value;
            }
        }

        public string Qihao
        {
            get
            {
                return this._m_CurrentPlayDataInfo.CurrentPlayData.Qh;
            }
        }
    }
}
